// import 'dart:io' show Platform;

// import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

/* 👉路由表 */
import 'package:kong/routes/app_pages.dart';
/* 👉主题 */
import 'package:kong/app/theme/app_theme.dart';
/* 👉翻译器 */
import 'package:kong/app/lang/translation_service.dart';
/* 👉Logger */
import 'package:kong/app/logger/logger.dart';
/* 👉initialBinding */
import 'package:kong/mian_binding.dart';

void main() async {
  // 基于Widgets框架的应用程序的具体绑定。是将框架绑定到Flutter引擎的粘合剂。
  WidgetsFlutterBinding.ensureInitialized();

  runApp(App());

  // 设置Android头部的导航栏透明
  // if (Platform.isAndroid) {
  //   SystemUiOverlayStyle systemUiOverlayStyle =
  //       SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  //   SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  // }
}

class App extends StatelessWidget {
  const App({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Kong',
      debugShowCheckedModeBanner: false, // 去掉debug图标
      /* 全局手势: 点击收起键盘 */
      builder: (context, child) => Scaffold(
        body: GestureDetector(
          onTap: () {
            hideKeyboard(context);
          },
          child: child,
        ),
      ),
      /* 👉Route */
      // home: Scaffold(),
      // home: SplashView(),
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      initialBinding: MainBinding(),
      unknownRoute: AppPages.unknownRoute,
      defaultTransition: Transition.fade,
      /* 👉theme */
      theme: AppTheme.theme,
      darkTheme: AppTheme.darkTheme,
      // themeMode: ThemeMode.dark,// 默认light
      /* 👉Locale */
      locale: TranslationService.locale,
      fallbackLocale: TranslationService.fallbackLocale,
      translations: TranslationService(),
      /* 👉Logger */
      enableLog: true,
      logWriterCallback: Logger.write,
    );
  }
}

void hideKeyboard(BuildContext context) {
  FocusScopeNode currentFocus = FocusScope.of(context);
  if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
    FocusManager.instance.primaryFocus?.unfocus();
  }
}
